<style>
    div[lay-id="replenishmentPlanTable"] .layui-table-cell,
    div[lay-id="replenishmentPlanTable"] .layui-form,
    div[lay-id="replenishmentPlanTable"] .layui-table-box,
    div[lay-id="replenishmentPlanTable"] .layui-table-body,
    div[lay-id="selfLoadPlanTable"] .layui-table-cell,
    div[lay-id="selfLoadPlanTable"] .layui-form,
    div[lay-id="selfLoadPlanTable"] .layui-table-box,
    div[lay-id="selfLoadPlanTable"] .layui-table-body {
        overflow: visible;
    }
    .storageWorkIsSelect .layui-table-cell{
        height: auto;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="code" class="layui-input" type="text" placeholder="请输入编号"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="cabinetLoadPlanBtnAddReplenishmentPlan" class="layui-btn icon-btn color-reseda">添加补货上货计划</button>
                            <button id="cabinetLoadPlanBtnAddSelfLoadPlan" class="layui-btn icon-btn color-reseda">添加自主上货计划</button>
                        </div>
                        <div class="lay-btn-rt">
                            <button id="cabinetLoadPlanBtnExport" class="layui-btn icon-btn layui-btn-danger">导出</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="cabinetLoadPlanTable" lay-filter="cabinetLoadPlanTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="cabinetLoadPlanTableBar">
    {{# if(d.status == "stayAudit"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="audit">审核</a>
    {{# } }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view">详情</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="cabinetLoadPlanForm">
    <form lay-filter="cabinetLoadPlanForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">创建者</label>
            <div class="layui-input-block">
                <input name="creator" placeholder="请输入创建者" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改者</label>
            <div class="layui-input-block">
                <input name="modifier" placeholder="请输入修改者" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人</label>
            <div class="layui-input-block">
                <input name="creatorName" placeholder="请输入创建人" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">修改人</label>
            <div class="layui-input-block">
                <input name="modifierName" placeholder="请输入修改人" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入编号" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="type">
                        <option value="replenishment">补货上货</option>
                        <option value="selfLoad">自主上货</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status">
                        <option value="stayAudit">待审核</option>
                        <option value="pass">审核通过</option>
                        <option value="fail">审核失败</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">配货需求订单ID</label>
            <div class="layui-input-block">
                <input name="distributionDemandId" placeholder="请输入配货需求订单ID" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">入驻企业ID</label>
            <div class="layui-input-block">
                <input name="companyId" placeholder="请输入入驻企业ID" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">接入柜子ID</label>
            <div class="layui-input-block">
                <input name="cabinetId" placeholder="请输入接入刀柜ID" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="cabinetLoadPlanFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 添加补货上货计划弹窗 -->
<script type="text/html" id="replenishmentPlanForm">
    <form lay-filter="storageWorkAddForm" class="layui-form model-form" style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-row table-bor storageWorkIsSelect">
                <table class="layui-table" id="replenishmentPlanTable" lay-filter="replenishmentPlanTable"></table>
            </div>
            <div id="cabinetLoadPlanDetails" style="height: 70%;overflow-y: scroll;">
                <table class="layui-table" id="distributionDemandDetailTable" lay-filter="distributionDemandDetailTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" id="submitPlan">提交计划</button>
        </div>
    </form>
</script>

<!-- 配货订单列表弹窗 -->
<script type="text/html" id="distributionDemandListAdd">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">配货订单编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="distCode" class="layui-input" type="text" placeholder="请输入配货订单编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="distributionDemandListAddFormSubSearchLog" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                            <button id="distributionDemandListAdd-btn-choose" class="layui-btn layui-btn-normal">确认选择</button>
                        </div>
                    </div>
                </div>

                <!-- 表格 -->
                <table class="layui-table" id="distributionDemandListAddTable" lay-filter="distributionDemandListAddTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- 计划领出数 -->
<script type="text/html" id="planLoadNum">
    {{# var planLoadNum = "";
        if(d.planLoadNum != null){
            planLoadNum = d.planLoadNum;
        }
    }}
    <div><input name="planLoadNum" placeholder="请输入数量" type="text" value="{{planLoadNum}}" lay-verify="integer" class="layui-input" maxlength="10" style="border: 0;height: 28px;" /></div>
</script>

<!-- 添加自主上货计划弹窗 -->
<script type="text/html" id="selfLoadPlanForm">
    <form lay-filter="storageWorkAddForm" class="layui-form model-form" style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-row table-bor storageWorkIsSelect">
                <table class="layui-table" id="selfLoadPlanTable" lay-filter="selfLoadPlanTable"></table>
            </div>
            <div id="cabinetCargoLanes" style="height: 60%;overflow-y: scroll;">
                <table class="layui-table" id="cabinetCargoLaneTable" lay-filter="cabinetCargoLaneTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" id="submit">提交</button>
        </div>
    </form>
</script>

<!-- 接入刀柜列表弹窗 -->
<script type="text/html" id="cabinetListAdd">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">柜子编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="code" class="layui-input" type="text" placeholder="请输入柜子编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="cabinetListAddFormSubSearchLog" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                            <button id="cabinetListAdd-btn-choose" class="layui-btn layui-btn-normal">确认选择</button>
                        </div>
                    </div>
                </div>

                <!-- 表格 -->
                <table class="layui-table" id="cabinetListAddTable" lay-filter="cabinetListAddTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- 仓库列表弹窗 -->
<script type="text/html" id="warehouseListAdd">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">名称：</label>
                            <div class="layui-input-inline mr0">
                                <input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">编码：</label>
                            <div class="layui-input-inline mr0">
                                <input name="code" class="layui-input" type="text" placeholder="请输入编码"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="warehouseListAddFormSubSearchLog" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                            <button id="warehouseListAdd-btn-choose" class="layui-btn layui-btn-normal">确认选择</button>
                        </div>
                    </div>
                </div>

                <!-- 表格 -->
                <table class="layui-table" id="warehouseListAddTable" lay-filter="warehouseListAddTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- 货道表格操作列 -->
<script type="text/html" id="cabinetCargoLaneTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="addPlan">添加计划</a>
</script>

<!-- 柜子货道上货表单弹窗 -->
<script type="text/html" id="cabinetCargoLaneLoadForm">
    <form lay-filter="cabinetCargoLaneLoadForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">柜子编号</label>
            <div class="layui-input-block">
                <input name="cabinetCode" readonly type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货道编号</label>
            <div class="layui-input-block">
                <input name="code" readonly type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">货道库容量</label>
            <div class="layui-input-block">
                <input name="quantity" readonly type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">已用库容量</label>
            <div class="layui-input-block">
                <input name="currentStockCount" readonly type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">可存放量</label>
            <div class="layui-input-block">
                <input name="storageCapacity" readonly type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择物料</label>
            <div class="layui-input-block">
                <select name="skuCode" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上货数量</label>
            <div class="layui-input-block">
                <input name="loadQuantity" type="text" class="layui-input" lay-verify="required|integer" required />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注说明</label>
            <div class="layui-input-block">
                <input name="remark" type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="cabinetCargoLaneLoadFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>


<!-- 详情 -->
<script type="text/html" id="cabinetLoadPlanView">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格 -->
                <table class="layui-table" id="cabinetLoadPlanViewTable" lay-filter="cabinetLoadPlanViewTable"></table>

                <!-- 表格 -->
                <div id="cabinetLoadPlanDetailsView" style="height: 60%;overflow-y: scroll;">
                    <table class="layui-table" id="cabinetLoadPlanDetailListTable" lay-filter="cabinetLoadPlanDetailListTable"></table>
                </div>

                <div class="layui-form-item text-center" style="margin-top: 30px;">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                    <button class="layui-btn" type="button" id="auditPass" style="display: none;">审核通过</button>
                    <button class="layui-btn layui-btn-danger" type="button" id="auditFail" style="display: none;">审核不通过</button>
                </div>
            </div>
        </div>
    </div>
</script>


<!--所属配货需求订单下拉框-->
<script type="text/html" id="distCodeTemplate">
    <form lay-filter="storageTypeForm" class="layui-form model-form" style="padding: 0;">
        <select name="distributionDemandCode" id="distCode" lay-filter="distCode" lay-verify="required"></select>
    </form>
</script>

<!--刀柜下拉框-->
<script type="text/html" id="cabinetCodeTemplate">
    <form lay-filter="storageTypeForm" class="layui-form model-form" style="padding: 0;">
        <select name="cabinetCode" id="cabinetCode" lay-filter="cabinetCode" lay-verify="required"></select>
    </form>
</script>

<!--选择领货仓库下拉框-->
<script type="text/html" id="warehouseNameTemplate">
    <form lay-filter="storageTypeForm" class="layui-form model-form" style="padding: 0;">
        <select name="warehouseId" id="warehouseName" lay-filter="warehouseName" lay-verify="required"></select>
    </form>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        // 渲染表格
        var insTb = table.render({
            elem: '#cabinetLoadPlanTable',
            url: config.base + 'enterprisecab/cabinet/admin/cabinetLoadPlan/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'}
                ,{field: 'code', sort: true, title: '上货计划编号'}
                ,{field: 'typeDesc', sort: true, title: '上货计划类型'}
                ,{field: 'distCode', sort: true, title: '所属配货需求订单'}
                ,{field: 'skuNum', sort: true, title: '物料数量'}
                ,{field: 'total', sort: true, title: '总货值'}
                ,{field: 'createTime', sort: true, title: '提交时间'}
                ,{field: 'statusDesc', sort: true, title: '状态'}
                ,{field: 'creatorName', sort: true, title: '操作员'}
                ,{align: 'center', toolbar: '#cabinetLoadPlanTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                /*var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }*/
            }
        });

        // 工具条点击事件
        table.on('tool(cabinetLoadPlanTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'audit') { // 审核
                showAuditModel(data);
            } else if (obj.event === 'view') { // 详情
                showViewModel(data);
            }
        });

        //监听排序
        table.on('sort(cabinetLoadPlanTable)', function(obj){
            table.reload('cabinetLoadPlanTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 添加补货上货计划按钮点击事件
        $('#cabinetLoadPlanBtnAddReplenishmentPlan').click(function () {
            showReplenishmentPlanModel();
        });

        // 添加自主上货计划按钮点击事件
        $('#cabinetLoadPlanBtnAddSelfLoadPlan').click(function () {
            showSelfLoadPlanModel();
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '700px',
                offset: '65px',
                title: data ? '修改上货计划' : '添加上货计划',
                content: $('#cabinetLoadPlanForm').html(),
                success: function () {
                    if (data){
                        var option = $("form select[name='type']").find("option");
                        layui.each(option, function(index, item){
                            if(data.type  == item.text){
                                data.type = item.value;
                            }
                        });
                    }

                    if (data){
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function(index, item){
                            if(data.status  == item.text){
                                data.status = item.value;
                            }
                        });
                    }

                    form.val('cabinetLoadPlanForm', data);
                    // 表单提交事件
                    form.on('submit(cabinetLoadPlanFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/cabinet/admin/cabinetLoadPlan/update' : 'enterprisecab/cabinet/admin/cabinetLoadPlan/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cabinetLoadPlanTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 显示详情弹窗
        function showViewModel(data) {
            admin.open({
                type: 1,
                area: ['75%', '80%'],
                offset: '65px',
                title: '上货计划详情',
                content: $('#cabinetLoadPlanView').html(),
                success: function () {
                    var cols = [];
                    var detailCols = [];
                    if(data.type == "replenishment"){ // 补货上货
                        cols = [
                            {field: 'code', title: '上货计划单编号'}
                            ,{field: 'distCode', title: '所属配货需求订单'}
                            ,{field: 'skuNum', title: '物料数量'}
                            ,{field: 'total', title: '总货值'}
                            ,{field: 'createTime', title: '提交时间'}
                            ,{field: 'statusDesc', title: '状态'}
                            ,{field: 'creatorName', title: '操作员'}
                        ];
                        detailCols = [
                            {field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'productName', sort: true, title: '物料名称'}
                            // ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuSpecValueNames', sort: true, title: '规格'}
                            ,{field: 'unitName', sort: true, title: '单位'}
                            ,{field: 'planReplenishment', sort: true, title: '需求数量'}
                            ,{field: 'quantity', sort: true, title: '计划上货数'}
                        ];
                    }else{ // 自主上货
                        cols = [
                            {field: 'code', title: '上货计划单编号'}
                            ,{field: 'cabinetCode', title: '柜子编号'}
                            ,{field: 'warehouseName', title: '领货仓库'}
                            ,{field: 'laneNum', title: '货道数'}
                            ,{field: 'spaceNum', title: '货位数'}
                            ,{field: 'alarmSkuNum', title: '告警数'}
                            /*,{field: 'remark', title: '备注'}
                            ,{field: 'creatorName', title: '刀柜管理员'}
                            ,{field: 'statusDesc', title: '管理员电话'}*/
                            ,{field: 'statusDesc', title: '柜子状态'}
                        ];
                        detailCols = [
                            {field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'productName', sort: true, title: '物料名称'}
                            // ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuSpecValueNames', sort: true, title: '规格'}
                            ,{field: 'unitName', sort: true, title: '单位'}
                            ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'quantity', sort: true, title: '计划上货数'}
                        ];
                    }

                    // 渲染表格
                    var insTb = table.render({
                        elem: '#cabinetLoadPlanViewTable',
                        data: [data],
                        limit: 1,
                        page: false,
                        cellMinWidth: 100,
                        cols: [cols]
                    });

                    // 查询上货计划明细数据
                    admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/cabinetLoadPlanDetailList',
                        {cabinetLoadPlanId: data.id, type: data.type, limit:9999}, function (res) {
                        if (200 == res.code) {
                            // 渲染表格
                            var insTb = table.render({
                                elem: '#cabinetLoadPlanDetailListTable',
                                data: res.data,
                                // limit: 1,
                                page: false,
                                cellMinWidth: 100,
                                cols: [detailCols]
                            });
                        } else {
                            layer.msg('获取上货计划明细失败', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                }
            });
        }

        // 显示审核弹窗
        function showAuditModel(data) {
            var auditModel = admin.open({
                type: 1,
                area: ['75%', '80%'],
                offset: '65px',
                title: '上货计划审核',
                content: $('#cabinetLoadPlanView').html(),
                success: function () {
                    $("#auditPass").show();
                    $("#auditFail").show();

                    var cols = [];
                    var detailCols = [];
                    if(data.type == "replenishment"){ // 补货上货
                        cols = [
                            {field: 'code', title: '上货计划单编号'}
                            ,{field: 'distCode', title: '所属配货需求订单'}
                            ,{field: 'skuNum', title: '物料数量'}
                            ,{field: 'total', title: '总货值'}
                            ,{field: 'createTime', title: '提交时间'}
                            ,{field: 'statusDesc', title: '状态'}
                            ,{field: 'creatorName', title: '操作员'}
                        ];
                        detailCols = [
                            {field: 'skuCode', sort: true, title: '物料编号'}
                            // ,{field: 'productCode', sort: true, title: '物料编号'}
                            ,{field: 'productName', sort: true, title: '物料名称'}
                            // ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuSpecValueNames', sort: true, title: '规格'}
                            ,{field: 'unitName', sort: true, title: '单位'}
                            ,{field: 'planReplenishment', sort: true, title: '需求数量'}
                            ,{field: 'quantity', sort: true, title: '计划上货数'}
                        ];
                    }else{ // 自主上货
                        cols = [
                            {field: 'code', title: '上货计划单编号'}
                            ,{field: 'cabinetCode', title: '柜子编号'}
                            ,{field: 'warehouseName', title: '领货仓库'}
                            ,{field: 'laneNum', title: '货道数'}
                            ,{field: 'spaceNum', title: '货位数'}
                            ,{field: 'alarmSkuNum', title: '告警数'}
                            /*,{field: 'remark', title: '备注'}
                            ,{field: 'creatorName', title: '刀柜管理员'}
                            ,{field: 'statusDesc', title: '管理员电话'}*/
                            ,{field: 'statusDesc', title: '柜子状态'}
                        ];
                        detailCols = [
                            {field: 'skuCode', sort: true, title: '物料编号'}
                            // ,{field: 'productCode', sort: true, title: '物料编号'}
                            ,{field: 'productName', sort: true, title: '物料名称'}
                            // ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'skuSpecValueNames', sort: true, title: '规格'}
                            ,{field: 'unitName', sort: true, title: '单位'}
                            ,{field: 'skuCode', sort: true, title: '物料编号'}
                            ,{field: 'quantity', sort: true, title: '计划上货数'}
                        ];
                    }

                    // 渲染表格
                    var insTb = table.render({
                        elem: '#cabinetLoadPlanViewTable',
                        data: [data],
                        limit: 1,
                        page: false,
                        cellMinWidth: 100,
                        cols: [cols]
                    });

                    // 查询上货计划明细数据
                    admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/cabinetLoadPlanDetailList',
                        {cabinetLoadPlanId: data.id, type: data.type, limit:9999}, function (res) {
                        if (200 == res.code) {
                            // 渲染表格
                            var insTb = table.render({
                                elem: '#cabinetLoadPlanDetailListTable',
                                data: res.data,
                                // limit: 1,
                                page: false,
                                cellMinWidth: 100,
                                cols: [detailCols]
                            });
                        } else {
                            layer.msg('获取上货计划明细失败', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 审核通过
                    $("#auditPass").click(function () {
                        layer.load(2);
                        admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/audit', {id: data.id, status: 'pass'}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(auditModel);
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cabinetLoadPlanTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    })

                    // 审核不通过
                    $("#auditFail").click(function () {
                        layer.load(2);
                        admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/audit', {id: data.id, status: 'fail'}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(auditModel);
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cabinetLoadPlanTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    })

                }
            });
        }

        // 显示补货上货计划弹窗
        function showReplenishmentPlanModel() {
            admin.open({
                type: 1,
                area: ['75%', '80%'],
                offset: '65px',
                title: '添加补货上货计划',
                content: $('#replenishmentPlanForm').html(),
                success: function () {
                    var datas = [{}];
                    var cabinetLoadPlan = {};
                    function distributionDemandDetailList(code, warehouseId) {
                        table.render({
                            elem: '#distributionDemandDetailTable',
                            url: config.base + 'enterprisecab/cabinet/admin/cabinetLoadPlan/distributionDemandDetailList',
                            where: {distCode: code, warehouseId: warehouseId, limit: 999999, isLoadPlanFinish: 1},
                            page: false,
                            cellMinWidth: 100,
                            cols: [[
                                // {field: 'id', sort: true, title: 'ID', hide: true}
                                {field: 'skuCode', sort: true, title: '物料编号'}
                                // ,{field: 'productCode', sort: true, title: '物料编号'}
                                ,{field: 'productName', sort: true, title: '物料名称'}
                                ,{field: 'skuSpecValueNames', sort: true, title: '规格'}
                                ,{field: 'unitName', sort: true, title: '单位'}
                                ,{field: 'planReplenishment', sort: true, title: '需求数量'}
                                ,{field: 'alreadyLoadPlanNum', sort: true, title: '已上货计划数'}
                                ,{field: 'surplusLoadPlanNum', sort: true, title: '剩余上货计划数'}
                                ,{field: 'currentStockCount', sort: true, title: '当前库存数'}
                                ,{field: 'planLoadNum', title: '计划上货数', templet: "#planLoadNum"}
                            ]]
                        });
                    }

                    // 渲染表格
                    var insTb = table.render({
                        elem: '#replenishmentPlanTable',
                        data: datas,
                        limit: datas.limit,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            // {field: 'distCode', title: '所属配货需求订单', templet: '<div><span class="distCode" style="display: block;cursor: pointer;" data-add="{{d.distCode != null ? false : true}}">{{d.distCode != null ? d.distCode : "请选择配货需求订单"}}</span></div>'},
                            // ,{field: 'warehouseName', title: '选择领货仓库', templet: '<div><span class="warehouseName" style="display: block;cursor: pointer;" data-add="{{d.warehouseName != null ? false : true}}">{{d.warehouseName != null ? d.warehouseName : "请选择领货仓库"}}</span></div>'}
                            {field: 'distCode', title: '所属配货需求订单', templet: '#distCodeTemplate', width: 220},
                            ,{field: 'warehouseName', title: '选择领货仓库', templet: '#warehouseNameTemplate', width: 220}
                            ,{field: 'warehouseId', title: '选择领货仓库ID', hide: true}
                            ,{field: 'stockNum', title: '物料数量'}
                            ,{field: 'cabNum', title: '需上货柜子数'}
                            ,{field: 'total', title: '总货值'}
                            ,{field: 'createTime', title: '提交时间'}
                            ,{field: 'statusDesc', title: '状态'}
                            ,{field: 'creatorName', title: '操作员'}
                        ]],
                        done: function (res, curr, count) {
                            // 获取所属配货需求订单
                            admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/distributionDemandList', {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    $('#distCode').append(new Option("请选择配货需求订单", ""));//往下拉菜单里添加元素
                                    $.each(res.data, function(index, item) {
                                        $('#distCode').append(new Option(item.distCode, item.distCode));//往下拉菜单里添加元素
                                    })
                                    form.render(); //菜单渲染 把内容加载进去

                                    // 选择配货需求订单
                                    form.on("select(distCode)", function (data) {
                                        var warehouseId = $("select[name='warehouseId']").val();
                                        var stockNum = $(data.elem).parent().parent().parent().next().next().next().find("div");
                                        var cabNum = $(data.elem).parent().parent().parent().next().next().next().next().find("div");
                                        var total = $(data.elem).parent().parent().parent().next().next().next().next().next().find("div");
                                        var createTime = $(data.elem).parent().parent().parent().next().next().next().next().next().next().find("div");
                                        var statusDesc = $(data.elem).parent().parent().parent().next().next().next().next().next().next().next().find("div");
                                        var creatorName = $(data.elem).parent().parent().parent().next().next().next().next().next().next().next().next().find("div");
                                        if (data.value != "") {
                                            $.each(res.data, function(index, item) {
                                                if(item.distCode == data.value){
                                                    cabinetLoadPlan.distributionDemandId = item.id;
                                                    stockNum.text(item.stockNum);
                                                    cabNum.text(item.cabNum);
                                                    total.text(item.total);
                                                    createTime.text(item.createTime);
                                                    statusDesc.text(item.statusDesc);
                                                    creatorName.text(item.creatorName);
                                                }
                                            })
                                        } else {
                                            cabinetLoadPlan.distributionDemandId = "";
                                        }
                                        if(data.value != "" && warehouseId != ""){
                                            distributionDemandDetailList(data.value, warehouseId);
                                        }
                                    })
                                } else {
                                    layer.msg("获取所属配货需求订单失败", {icon: 2});
                                }
                            }, 'GET');

                            // 获取领货仓库
                            admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/warehouseList', {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    $('#warehouseName').append(new Option("请选择领货仓库", ""));//往下拉菜单里添加元素
                                    $.each(res.data, function(index, item) {
                                        $('#warehouseName').append(new Option(item.name, item.id));//往下拉菜单里添加元素
                                    })
                                    form.render(); //菜单渲染 把内容加载进去

                                    // 选择配货需求订单
                                    form.on("select(warehouseName)", function (data) {
                                        // var distCode = $(data.elem).parent().parent().parent().prev().find("input").val();
                                        var distCode = $("select[name='distributionDemandCode']").val();
                                        if (data.value != "") {
                                            $.each(res.data, function(index, item) {
                                                if(item.id == data.value){
                                                    cabinetLoadPlan.warehouseId = item.id;
                                                }
                                            })
                                        } else {
                                            cabinetLoadPlan.warehouseId = "";
                                        }
                                        if(data.value != "" && distCode != ""){
                                            distributionDemandDetailList(distCode, data.value);
                                        }
                                    })
                                } else {
                                    layer.msg("获取领货仓库失败", {icon: 2});
                                }
                            }, 'GET');
                        }
                    });

                    // 表单提交事件
                    $("#submitPlan").click(function () {
                        layer.load(2);
                        var cabinetLoadPlanDetails = [];
                        console.log(cabinetLoadPlan);
                        if($.isEmptyObject(cabinetLoadPlan)){
                            layer.closeAll('loading');
                            layer.msg("请选择配货需求订单", {icon: 2});
                            return false;
                        }
                        if(cabinetLoadPlan.warehouseId == undefined){
                            layer.closeAll('loading');
                            layer.msg("请选择领货仓库", {icon: 2});
                            return false;
                        }
                        var addNum = 0;
                        var isJump = false;
                        var regular = /^[1-9]\d*$/; // 大于0的整数正则表达式
                        cabinetLoadPlan.type = "replenishment"; // 补货上货
                        $("#cabinetLoadPlanDetails").find("tbody tr").each(function (index, item) {
                            var cabinetLoadPlanDetail = {};
                            $(item).find("td").each(function (detailIndex, detailItem) {
                                if($(detailItem).data("field") == "id"){
                                    cabinetLoadPlanDetail.distributionDemandDetailId = $(detailItem).find("div").text();
                                }else if($(detailItem).data("field") == "skuCode"){
                                    cabinetLoadPlanDetail.skuCode = $(detailItem).find("div").text();
                                }else if($(detailItem).data("field") == "planLoadNum"){
                                    if($(detailItem).find("input").val()){
                                        addNum++;
                                        if(!regular.test($(detailItem).find("input").val())){
                                            layer.msg("计划上货数格式错误，请输入大于0的整数", {icon: 2});
                                            isJump = true;
                                            return false;
                                        }
                                    }
                                    var planLoadNum = parseInt($(detailItem).find("input").val()); // 计划上货数
                                    cabinetLoadPlanDetail.quantity = planLoadNum;
                                    // 判断计划上货数是否满足要求
                                    var planReplenishment = parseInt($(detailItem).prev().prev().prev().prev().find("div").text()); // 需求数量
                                    var alreadyLoadPlanNum = parseInt($(detailItem).prev().prev().prev().find("div").text()); // 已上货计划数
                                    var surplusLoadPlanNum = parseInt($(detailItem).prev().prev().find("div").text()); // 剩余上货计划数
                                    var currentStockCount = parseInt($(detailItem).prev().find("div").text()); // 当前库存数
                                    // 判断是否上货完成
                                    /*if(planReplenishment == alreadyLoadPlanNum){
                                        if(planLoadNum != ""){
                                            layer.msg("该物料已经上货完成，请确认！", {icon: 2});
                                            isJump = true;
                                            return false;
                                        }
                                    }*/
                                    // 未上货完成
                                    if(planReplenishment > alreadyLoadPlanNum){
                                        if(surplusLoadPlanNum <= currentStockCount){ // 剩余上货计划数小于等于当前库存数
                                            if(planLoadNum > surplusLoadPlanNum){ // 判断计划上货数是否大于剩余上货计划数
                                                layer.msg("计划上货数不能大于剩余上货计划数", {icon: 2});
                                                isJump = true;
                                                return false;
                                            }
                                        }else{ // 剩余上货计划数大于当前库存数
                                            if(planLoadNum > currentStockCount){ // 判断计划上货数是否大于当前库存数
                                                layer.msg("计划上货数不能大于当前库存数", {icon: 2});
                                                isJump = true;
                                                return false;
                                            }
                                        }
                                    }
                                }
                            })
                            if(cabinetLoadPlanDetail.quantity){
                                cabinetLoadPlanDetails.push(cabinetLoadPlanDetail);
                            }
                        })
                        if(isJump){
                            layer.closeAll('loading');
                            return false;
                        }
                        if(addNum == 0){
                            layer.closeAll('loading');
                            layer.msg("请至少输入一条计划上货数", {icon: 2});
                            return false;
                        }
                        cabinetLoadPlan.cabinetLoadPlanDetailForms = cabinetLoadPlanDetails;
                        admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/add', JSON.stringify(cabinetLoadPlan), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cabinetLoadPlanTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    })
                }
            });
        }

        // 显示自主上货计划弹窗
        function showSelfLoadPlanModel() {
            admin.open({
                type: 1,
                area: ['75%', '80%'],
                offset: '65px',
                title: '添加自主上货计划',
                content: $('#selfLoadPlanForm').html(),
                success: function () {
                    var datas = [{}];
                    var cabinetLoadPlan = {};
                    function cabinetCargoLaneList(code, warehouseId) {
                        table.render({
                            elem: '#cabinetCargoLaneTable',
                            url: config.base + 'enterprisecab/cabinet/admin/cabinetLoadPlan/cabinetCargoLaneList',
                            where: {cabCode: code, warehouseId: warehouseId, limit: 999999, isFilterCargoLane: 1},
                            page: false,
                            cellMinWidth: 100,
                            cols: [[
                                {field: 'id', sort: true, title: 'ID', hide: true}
                                ,{field: 'code', sort: true, title: '货道编号'}
                                ,{field: 'statusDesc', sort: true, title: '状态'}
                                ,{field: 'quantity', sort: true, title: '货道库容量'}
                                ,{field: 'currentStockCount', sort: true, title: '已用库容量'}
                                ,{field: 'productName', sort: true, title: '当前存放物料'}
                                ,{field: 'skuCode', sort: true, title: '物料编号'}
                                ,{field: 'brandName', sort: true, title: '品牌'}
                                ,{field: 'stockStatusDesc', sort: true, title: '库存状态'}
                                ,{field: 'storageCapacity', sort: true, title: '可存放量'}
                                ,{field: 'loadQuantity', sort: true, title: '上货数量'}
                                ,{field: 'illustrate', sort: true, title: '备注说明', hide: true}
                                ,{align: 'center', toolbar: '#cabinetCargoLaneTableBar', title: '操作', width: 200}
                            ]]
                        });

                        // 工具条点击事件
                        table.on('tool(cabinetCargoLaneTable)', function (obj) {
                            var data = obj.data;
                            var index = $(obj.tr).data("index");
                            if (obj.event === 'addPlan') { //添加计划
                                showAddPlanModel(index, data);
                            }
                        });

                        // 显示编辑弹窗
                        function showAddPlanModel(index, data) {
                            var $index = index;
                            var cabinetCargoLaneLoadForm = admin.open({
                                type: 1,
                                area: '700px',
                                offset: '65px',
                                title: '柜子货道上货管理',
                                content: $('#cabinetCargoLaneLoadForm').html(),
                                success: function () {
                                    form.render();
                                    data.cabinetCode = code;
                                    form.val('cabinetCargoLaneLoadForm', data);
                                    // 判断已用库容量是否为0
                                    if(data.currentStockCount != 0){
                                        $("select[name='skuCode']").attr("disabled", true).removeAttr("lay-search");
                                    }

                                    form.verify({
                                        integer: [/^[1-9]\d*$/, '请输入大于0的整数'],
                                    });

                                    // 获取物料明细
                                    admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/productDetailList',
                                        {limit:9999, cabCode: code, spaceCode: data.code, warehouseId: warehouseId}, function (res) {
                                        if (200 == res.code) {
                                            var optionHtml='<option value="">请选择物料</option>';
                                            for(var k=0;k<res.data.length;k++){
                                                optionHtml+='<option value="'+res.data[k].skuCode+'">'+res.data[k].skuCode+'</option>';
                                            }
                                            $("select[name='skuCode']").html(optionHtml);
                                            form.render('select');
                                            if(data && data.skuCode){
                                                form.val('cabinetCargoLaneLoadForm', data);
                                            }
                                        } else {
                                            layer.msg('获取物料失败', {icon: 2, time: 1000});
                                        }
                                    }, 'GET');

                                    // 表单提交事件
                                    form.on('submit(cabinetCargoLaneLoadFormSubmit)', function (d) {
                                        var storageCapacity = parseInt(d.field.storageCapacity); // 可存放量
                                        var loadQuantity = parseInt(d.field.loadQuantity); // 上货数量
                                        var remark = d.field.remark; // 备注
                                        var skuCode = d.field.skuCode; // sku编号
                                        if(loadQuantity > storageCapacity){
                                            layer.msg("上货数量不能大于可存放量", {icon: 2});
                                            return false;
                                        }
                                        $("#cabinetCargoLanes").find("tbody tr").each(function (index, item) {
                                            if($index == index){
                                                $(item).find("td").each(function (tdIndex, tdItem) {
                                                    if($(tdItem).data("field") == "loadQuantity"){ //定位上货数量
                                                        $(tdItem).find("div").text(loadQuantity);
                                                    }else if($(tdItem).data("field") == "illustrate"){
                                                        $(tdItem).find("div").text(remark);
                                                    }else if($(tdItem).data("field") == "skuCode"){
                                                        $(tdItem).find("div").text(skuCode);
                                                    }
                                                })
                                            }
                                        })
                                        layer.close(cabinetCargoLaneLoadForm);
                                        return false;
                                    });

                                }
                            });
                        }
                    }

                    // 渲染表格
                    var insTb = table.render({
                        elem: '#selfLoadPlanTable',
                        data: datas,
                        limit: datas.limit,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            // ,{field: 'cabinetCode', title: '选择柜子编号', templet: '<div><span class="cabinetCode" style="display: block;cursor: pointer;" data-add="{{d.cabinetCode != null ? false : true}}">{{d.cabinetCode != null ? d.cabinetCode : "请选择刀柜"}}</span></div>'}
                            // ,{field: 'warehouseName', title: '选择领货仓库', templet: '<div><span class="warehouseName" style="display: block;cursor: pointer;" data-add="{{d.warehouseName != null ? false : true}}">{{d.warehouseName != null ? d.warehouseName : "请选择领货仓库"}}</span></div>'}
                            {field: 'cabinetCode', title: '选择柜子编号', templet: '#cabinetCodeTemplate', width: 220}
                            ,{field: 'warehouseName', title: '选择领货仓库', templet: '#warehouseNameTemplate', width: 220}
                            ,{field: 'warehouseId', title: '选择领货仓库ID', hide: true}
                            ,{field: 'laneNum', title: '货道数'}
                            ,{field: 'spaceNum', title: '货位数'}
                            ,{field: 'alarmSkuNum', title: '告警数'}
                            ,{field: 'remark', title: '备注'}
                            /*,{field: 'creatorName', title: '刀柜管理员'}
                            ,{field: 'statusDesc', title: '管理员电话'}*/
                            ,{field: 'statusDesc', title: '柜子状态'}
                        ]],
                        done: function (res, curr, count) {
                            // 获取刀柜
                            admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/cabinetList', {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    $('#cabinetCode').append(new Option("请选择柜子", ""));//往下拉菜单里添加元素
                                    $.each(res.data, function(index, item) {
                                        $('#cabinetCode').append(new Option(item.code, item.code));//往下拉菜单里添加元素
                                    })
                                    form.render(); //菜单渲染 把内容加载进去

                                    // 选择刀柜
                                    form.on("select(cabinetCode)", function (data) {
                                        var warehouseId = $("select[name='warehouseId']").val();
                                        var laneNum = $(data.elem).parent().parent().parent().next().next().next().find("div");
                                        var spaceNum = $(data.elem).parent().parent().parent().next().next().next().next().find("div");
                                        var alarmSkuNum = $(data.elem).parent().parent().parent().next().next().next().next().next().find("div");
                                        var remark = $(data.elem).parent().parent().parent().next().next().next().next().next().next().find("div");
                                        var statusDesc = $(data.elem).parent().parent().parent().next().next().next().next().next().next().next().find("div");
                                        if (data.value != "") {
                                            $.each(res.data, function(index, item) {
                                                if(item.code == data.value){
                                                    cabinetLoadPlan.cabinetId = item.id;
                                                    laneNum.text(item.laneNum);
                                                    spaceNum.text(item.spaceNum);
                                                    alarmSkuNum.text(item.alarmSkuNum);
                                                    remark.text(item.remark);
                                                    statusDesc.text(item.statusDesc);
                                                }
                                            })
                                        } else {
                                            cabinetLoadPlan.cabinetId = "";
                                        }
                                        if(data.value != "" && warehouseId != ""){
                                            // 货道渲染表格
                                            cabinetCargoLaneList(data.value, warehouseId);
                                        }
                                    })
                                } else {
                                    layer.msg("获取柜子失败", {icon: 2});
                                }
                            }, 'GET');

                            // 获取领货仓库
                            admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/warehouseList', {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    $('#warehouseName').append(new Option("请选择领货仓库", ""));//往下拉菜单里添加元素
                                    $.each(res.data, function(index, item) {
                                        $('#warehouseName').append(new Option(item.name, item.id));//往下拉菜单里添加元素
                                    })
                                    form.render(); //菜单渲染 把内容加载进去

                                    // 选择配货需求订单
                                    form.on("select(warehouseName)", function (data) {
                                        var cabinetCode = $("select[name='cabinetCode']").val();
                                        if (data.value != "") {
                                            $.each(res.data, function(index, item) {
                                                if(item.id == data.value){
                                                    cabinetLoadPlan.warehouseId = item.id;
                                                }
                                            })
                                        } else {
                                            cabinetLoadPlan.warehouseId = "";
                                        }
                                        if(data.value != "" && cabinetCode != ""){
                                            cabinetCargoLaneList(cabinetCode, data.value);
                                        }
                                    })
                                } else {
                                    layer.msg("获取领货仓库失败", {icon: 2});
                                }
                            }, 'GET');
                        }
                    });

                    // 表单提交事件
                    $("#submit").click(function () {
                        layer.load(2);
                        var cabinetLoadPlanDetails = [];
                        if($.isEmptyObject(cabinetLoadPlan) || cabinetLoadPlan.cabinetId == undefined){
                            layer.closeAll('loading');
                            layer.msg("请选择柜子", {icon: 2});
                            return false;
                        }
                        if(cabinetLoadPlan.warehouseId == undefined){
                            layer.closeAll('loading');
                            layer.msg("请选择领货仓库", {icon: 2});
                            return false;
                        }
                        var addNum = 0;
                        cabinetLoadPlan.type = "selfLoad"; // 自主上货
                        $("#cabinetCargoLanes").find("tbody tr").each(function (index, item) {
                            var cabinetLoadPlanDetail = {};
                            $(item).find("td").each(function (detailIndex, detailItem) {
                                if($(detailItem).data("field") == "id"){
                                    cabinetLoadPlanDetail.cabinetCargoLaneId = $(detailItem).find("div").text(); // 货道ID
                                }else if($(detailItem).data("field") == "loadQuantity"){
                                    if($(detailItem).find("div").text()){
                                        addNum++;
                                        var loadQuantity = parseInt($(detailItem).find("div").text()); // 上货数量
                                        cabinetLoadPlanDetail.quantity = loadQuantity;
                                    }
                                }else if($(detailItem).data("field") == "illustrate"){
                                    cabinetLoadPlanDetail.remark = $(detailItem).find("div").text(); // 备注
                                }else if($(detailItem).data("field") == "skuCode"){
                                    cabinetLoadPlanDetail.skuCode = $(detailItem).find("div").text(); // 物料编号
                                }
                            })
                            if(cabinetLoadPlanDetail.quantity){
                                cabinetLoadPlanDetails.push(cabinetLoadPlanDetail);
                            }
                        })
                        if(addNum == 0){
                            layer.closeAll('loading');
                            layer.msg("请至少添加一条上货计划", {icon: 2});
                            return false;
                        }
                        cabinetLoadPlan.cabinetLoadPlanDetailForms = cabinetLoadPlanDetails;
                        admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/add', JSON.stringify(cabinetLoadPlan), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('cabinetLoadPlanTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    })
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/cabinetLoadPlan/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#cabinetLoadPlanBtnExport').click(function () {
            var checkRows = table.checkStatus('cabinetLoadPlanTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>